starter.controller('resCheckCtrl', ['$rootScope','$window','$state','$ionicHistory','$timeout','$ionicScrollDelegate', '$scope','XCode', 'Page',
    function($rootScope,$window,$state,$ionicHistory,$timeout,$ionicScrollDelegate, $scope, XCode,Page) {
        $scope._pageSize = 10;
        $scope._pageIndex = 0;
        $scope.search = {};
        $scope.search.queryType = '1';
        //$scope.resCheckQuery = function() {
        //    $scope.search.searchValue = $('#showText').val();
        //    Page.ajaxPostQuiet('web/resCheckQuery.do', {param : $scope.search.searchValue,queryType : $scope.search.queryType,
        //        _pageSize : $scope._pageSize, _pageIndex : $scope._pageIndex}, function (resp) {
        //        $scope.resList = resp.data.rows;
        //    });
        //}

        //定义自动查询
        $scope.autoSearch = {

        }

        changeSelect = function(obj,type) {
            $scope.search.queryType = type;
            if($scope.resList != undefined && $scope.resList.length > 0) {
                $scope.resList = [];
            }
            if($scope.search.queryType == "2") {
                $(obj).find("a").css("color","#2D99F4");
                $(obj).find("a").next().css("display","block");
                $(obj).prev().find("a").next().css("display","none");
                $(obj).prev().find("a").css("color","#9F9F9F");
                $scope.autoSearch.setPlaceholder("名称/街道/行向");
            } else if($scope.search.queryType == "1") {
                $(obj).find("a").css("color","#2D99F4");
                $(obj).find("a").next().css("display","block");
                $(obj).next().find("a").next().css("display","none");
                $(obj).next().find("a").css("color","#9F9F9F");
                $scope.autoSearch.setPlaceholder("车牌号/自编号/线路");
            }
            $("#showText").val("");
            $("#autoText").find("div").each(function(){
                $(this).remove();
            })

            $scope.$apply($scope.search.queryType);
        }


        $scope.changeSearchVal = function(selectVal) {
            Page.ajaxPostQuiet('web/resCheckQuery.do', {param : selectVal,queryType : $scope.search.queryType,
                _pageSize : $scope._pageSize, _pageIndex : $scope._pageIndex}, function (resp) {
                $scope.resList = resp.data.rows;
            });
        }

        $scope.viewResCheckDetail = function(resData) {
            $state.go("resCheckDetail",{resourceId : resData.resourceId});
        }

    }]);
